package com.example.android.criminalintent;

import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import static com.example.android.criminalintent.PictureUtils.*;

/**
 * Created by fulinux on 2017/11/30.
 */

public class PhotoDialogFragment extends DialogFragment {
    private ImageView mImageView;
    private static final String ARG_File = "file";

    public static PhotoDialogFragment newInstance(String path) {
        Bundle args = new Bundle();
        args.putSerializable(ARG_File, path);

        PhotoDialogFragment photoDialogFragment = new PhotoDialogFragment();
        photoDialogFragment.setArguments(args);
        return photoDialogFragment;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        //获取到之前传过来的路径
        String path = (String)getArguments().getSerializable(ARG_File);

        View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_photo, null);
        mImageView = (ImageView) view.findViewById(R.id.crime_full_photo);

        mImageView.setImageBitmap(getScaledBitmap(path, getActivity()));

        return new AlertDialog.Builder(getActivity())
                .setView(view)
                .setPositiveButton(android.R.string.ok, null)
                .create();
    }
}
